import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/enum_entity.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/utils/toast_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/image/local_image.dart';
import 'package:library_base/utils/get_util.dart';

class OrderScreeningDialog extends StatefulWidget {
  const OrderScreeningDialog({
    Key? key,
  }) : super(key: key);

  @override
  State<OrderScreeningDialog> createState() => _OrderScreeningDialogState();
}

class _OrderScreeningDialogState extends State<OrderScreeningDialog> {

  PaymentStatus? paymentStatus;

  Function(String)? filter;

  Function()? reset;

  @override
  void initState() {
    super.initState();
    if(Get.arguments['PaymentStatus']==PaymentStatus.NOT_PAY.name){
      paymentStatus = PaymentStatus.NOT_PAY;
    }else if(Get.arguments['PaymentStatus']==PaymentStatus.APPLICATION_PAYMENT.name){
      paymentStatus = PaymentStatus.APPLICATION_PAYMENT;
    }
    else if(Get.arguments['PaymentStatus']==PaymentStatus.HAVE_PAY.name){
      paymentStatus = PaymentStatus.HAVE_PAY;
    }
    filter = Get.arguments['filter'];
    reset = Get.arguments['reset'];
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        GetHelper.back();
      },
      child: Material(
        color: Colors.transparent,
        child: Container(
          color: Colors.transparent,
          child: GestureDetector(
            onTap: () {},
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  width: 0.88.sw,
                  decoration: rs8,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      gapH36,
                      SizedBox(
                        width: double.infinity,
                        child: Stack(
                          children: [
                            Container(
                                alignment: Alignment.center,
                                child: Text(MultiLanguage.orderStatus.tr, style: normalBoldTextColor32)),
                            Positioned(
                              right: 24.w,
                              child: GestureDetector(
                                onTap: () => Get.back(),
                                child: LocalImage('common_close',
                                    package: Constant.packLib(), width: 26.r, height: 26.r),
                              ),
                            )
                          ],
                        ),
                      ),
                      gapH24,
                      line1,
                      gapH40,
                      GestureDetector(
                        onTap: () {

                        },
                        child: Container(
                            alignment: Alignment.center,
                            width: double.infinity,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                gapW18,
                                Expanded(
                                  child: GestureDetector(
                                    onTap: (){
                                      _choose(PaymentStatus.NOT_PAY);
                                    },
                                    child: Container(
                                      decoration: _getBoxDecoration(paymentStatus == PaymentStatus.NOT_PAY),
                                      padding: EdgeInsets.symmetric(vertical: 24.w),
                                      alignment: Alignment.center,
                                      // width: double.infinity,
                                      child: Text(
                                        MultiLanguage.notApplied.tr,
                                        style: _getTextStyles(paymentStatus == PaymentStatus.NOT_PAY),
                                        textAlign: TextAlign.start,
                                      ),
                                    ),
                                  ),
                                ),
                                gapW18,
                                Expanded(
                                  child: GestureDetector(
                                    onTap: (){
                                      _choose(PaymentStatus.APPLICATION_PAYMENT);
                                    },
                                    child: Container(
                                      decoration: _getBoxDecoration(paymentStatus == PaymentStatus.APPLICATION_PAYMENT),
                                      padding: EdgeInsets.symmetric(vertical: 24.w),
                                      alignment: Alignment.center,
                                      // width: double.infinity,
                                      child: Text(
                                        MultiLanguage.applying.tr,
                                        style: _getTextStyles(paymentStatus == PaymentStatus.APPLICATION_PAYMENT),
                                        textAlign: TextAlign.start,
                                      ),
                                    ),
                                  ),
                                ),
                                gapW18,
                                Expanded(
                                  child: GestureDetector(
                                    onTap: (){
                                      _choose(PaymentStatus.HAVE_PAY);
                                    },
                                    child: Container(
                                      decoration: _getBoxDecoration(paymentStatus == PaymentStatus.HAVE_PAY),
                                      padding: EdgeInsets.symmetric(vertical: 24.w),
                                      alignment: Alignment.center,
                                      // width: double.infinity,
                                      child: Text(
                                        MultiLanguage.paymentReceived.tr,
                                        style: _getTextStyles(paymentStatus == PaymentStatus.HAVE_PAY),
                                        textAlign: TextAlign.start,
                                      ),
                                    ),
                                  ),
                                ),
                                gapW18,
                              ],
                            )),
                      ),
                      gapH40,
                      Container(
                        padding: edgeLR24,
                        child: Row(
                          children: [
                            Expanded(
                              child: GradientButton(
                                ThemeUtil.getTheme(),
                                radius: const BorderRadius.only(
                                    topLeft: Radius.circular(50), bottomLeft: Radius.circular(50)),
                                colors: ThemeUtil.getTheme().buttonLeftBgColor(),
                                height: 80.w,
                                text: MultiLanguage.reset.tr,
                                onPressed: () {
                                  GetHelper.back();
                                  reset?.call();
                                },
                              ),
                            ),

                            Expanded(
                              child: GradientButton(
                                ThemeUtil.getTheme(),
                                radius: const BorderRadius.only(
                                    topRight: Radius.circular(50),
                                    bottomRight: Radius.circular(50)),
                                height: 80.w,
                                text: MultiLanguage.filter.tr,
                                onPressed: () {
                                    if(paymentStatus == null){
                                      ToastUtil.normal(MultiLanguage.selectFilter.tr);
                                      return;
                                    }
                                    filter?.call(paymentStatus!.name);
                                    GetHelper.back();
                                },
                              ),
                            ),
                          ],
                        ),
                      ),
                      gapH36,
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  BoxDecoration _getBoxDecoration(bool isChoose){
    if(isChoose){
      return BoxDecoration(
        border: Border.fromBorderSide(BorderSide(color: ThemeUtil.getTheme().colorScheme.primary)),
        color: ThemeUtil.getTheme().fourthBgColor(),
        borderRadius: const BorderRadius.all(Radius.circular(30.0)),
      );
    }
    return BoxDecoration(
      color: ThemeUtil.getTheme().secondaryBgColor(),
      borderRadius: const BorderRadius.all(Radius.circular(30.0)),
    );
  }

  TextStyle _getTextStyles(bool isChoose){
    if(isChoose){
      return primaryTextColor28;
    }
    return normalTextColor28;
  }

  _choose(PaymentStatus paymentStatus){
    if(this.paymentStatus != paymentStatus){
      setState(() {
        this.paymentStatus = paymentStatus;
      });
    }
  }

}
